package com.seari.c3gallery.controller;

import com.seari.c3gallery.bean.DisplayPicBean;
import com.seari.c3gallery.main.StartUpClass;
import com.seari.c3gallery.pojo.MessageBean;
import com.seari.c3gallery.service.C3GalleryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class C3GalleryController {

    @Autowired
    C3GalleryService c3GalleryService;

    @Autowired
    public SimpMessagingTemplate template;

    @RequestMapping(value = "/plan")
    @ResponseBody
    public MessageBean cmdContro(String sceneNO){
        MessageBean msgBean = new MessageBean();
//        String scene = StringUtils.substring(sceneNO, 3);

        switch (sceneNO) {
            case "1": case "2":
                template.convertAndSend("/reportMod",sceneNO);
                template.convertAndSend("/keyCmd","mod2");
                break;
            case "mod3": case "mod4":
                template.convertAndSend("/dailyMod",sceneNO);
                sceneNO = StringUtils.substring(sceneNO, 3);
                break;
        }

        StartUpClass.client.callScene(sceneNO);
        System.out.println("sceneNO = " + sceneNO);
        msgBean.setCode("1000");
        msgBean.setMessage("切换指令成功！");
        return msgBean;
    }

    @RequestMapping(value = "/pic")
    @ResponseBody
    public MessageBean picList(){
        MessageBean msgBean = new MessageBean();
        List<DisplayPicBean> displayPicBeans = c3GalleryService.fetchDisplayPicList();
        msgBean.setData(displayPicBeans);
        msgBean.setCode("1000");
        msgBean.setMessage("获取展示页图片成功！");
        return msgBean;
    }



    @RequestMapping(value = "/ppt")
    public String webPPT(){
        return "webPPT";
    }

    public static void main(String[] args) {
        String s = "mod16";
        String substring = StringUtils.substring(s, 3);
        System.out.println("substring = " + substring);
    }
}
